package com.taiyo.modules.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.taiyo.modules.api.entity.TOrderEntity;
import com.taiyo.modules.api.service.TOrderService;
import com.taiyo.common.utils.PageUtils;
import com.taiyo.common.utils.Query;
import com.taiyo.common.utils.R;




/**
 * 订单
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-01-29 10:41:15
 */
@RestController
@RequestMapping("/api/torder")
public class TOrderController {
	@Autowired
	private TOrderService tOrderService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("api:torder:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TOrderEntity> tOrderList = tOrderService.queryList(query);
		int total = tOrderService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tOrderList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("api:torder:info")
	public R info(@PathVariable("id") Long id){
		TOrderEntity tOrder = tOrderService.queryObject(id);
		
		return R.ok().put("tOrder", tOrder);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("api:torder:save")
	public R save(@RequestBody TOrderEntity tOrder){
		tOrderService.save(tOrder);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("api:torder:update")
	public R update(@RequestBody TOrderEntity tOrder){
		tOrderService.update(tOrder);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("api:torder:delete")
	public R delete(@RequestBody Long[] ids){
		tOrderService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
